package com.platform.core.service.impl;

import com.platform.comm.service.impl.CommonBizImpl;
import com.platform.core.repository.NcloudSysUserPostRepository;
import com.querydsl.core.types.Predicate;
import com.platform.comm.dto.DtoMapper;
import com.platform.core.entity.NcloudSysUserPostEntity;
import com.platform.core.entity.QNcloudSysUserPostEntity;
import com.platform.core.service.NcloudSysUserPostBiz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Description: NcloudSysUserPostion-业务接口实现类
 *
 * @author Coder
 */
@Slf4j
@Service
public class NcloudSysUserPostBizImpl extends CommonBizImpl<NcloudSysUserPostRepository, NcloudSysUserPostEntity, String> implements NcloudSysUserPostBiz {

    private final QNcloudSysUserPostEntity qNcloudSysUserPostion = QNcloudSysUserPostEntity.ncloudSysUserPostEntity;
    private final DtoMapper mapper;

    public NcloudSysUserPostBizImpl(NcloudSysUserPostRepository ncloudSysUserPostionRepository, DtoMapper mapper) {
        super(ncloudSysUserPostionRepository);
        this.mapper = mapper;
    }

    @Override
    public Page<NcloudSysUserPostEntity> search(Predicate predicate, Pageable pageable){
        Page<NcloudSysUserPostEntity> page = queryByPage(predicate, pageable);
        return page.map(entity -> mapper.map(entity, NcloudSysUserPostEntity.class));
    }

    @Override
    public NcloudSysUserPostEntity detail(String id) {
        return mapper.map(fetchById(id), NcloudSysUserPostEntity.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(NcloudSysUserPostEntity req) {
        NcloudSysUserPostEntity entity = mapper.map(req, NcloudSysUserPostEntity.class);
        saveEntity(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void modify(NcloudSysUserPostEntity req) {
        NcloudSysUserPostEntity entity = fetchById(req.getId());
        mapper.map(req, entity);
        saveEntity(entity);
    }

    @Override
    public void batchRemove(List<NcloudSysUserPostEntity> userPostList) {
        repository.deleteAll(userPostList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void remove(String id){
        repository.deleteById(id);
    }
}
